package ui.component
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.display.Sprite;

	import globals.Global;

	/**
	 * 竖直的进度条。 附：目前用在强化界面的温度计
	 * @author luguobin
	 */
	public class VBar extends Sprite
	{
		private var _current:Number;
		private var _max:Number;
		private var _track:Bitmap;
		private var _bg:Bitmap;
		private var _mask:Shape;

		public function VBar()
		{
			_bg = new Bitmap(Global.assetsManager.getAssetsAsBitmapData("equipLevelUp_temperature_bg"));
			this.addChild(_bg);

			_track = new Bitmap();
			_track.x = 6;
			_track.y = 6;
			this.addChild(_track);

			_mask = new Shape();
			this.addChild(_mask);
			_track.mask = _mask;
		}

		public function update(value:Number, max:Number, isUp:Boolean = true):void
		{
			_max = max;
			_current = Math.min(value, _max);

			if(isUp)
			{
				_track.bitmapData = Global.assetsManager.getAssetsAsBitmapData("equipLevelUp_temperature_rise");
			}
			else
			{
				_track.bitmapData = Global.assetsManager.getAssetsAsBitmapData("equipLevelUp_temperature_drop");
			}
			updateBar();
		}

		private function updateBar():void
		{
			_mask.graphics.clear();
			_mask.graphics.beginFill(0xFFFFFF);
			var myHeight:Number = _current / _max * _track.height;
			_mask.graphics.drawRect(_track.x, _track.y + _track.height - myHeight, _track.width, myHeight);
			_mask.graphics.endFill();
		}

		public function clear():void
		{
			_bg.bitmapData = _track.bitmapData = null;
		}
	}
}